package linestrategy

import (
	"codejy/analysis/lineanalysis"
	"codejy/structdef"
	"strings"
)

// 全局文件方法调用策略 (不支持多线程)
type GlobalMethodStrategy struct {
}

// 注册策略
func init() {
	RegisterStrategy(&GlobalMethodStrategy{})
}

// 判断
func (f *GlobalMethodStrategy) getId() int {
	return lineanalysis.GlobalMethod
}

// 调用此方法必然在实例内部方法中,所以CurrentInstanceAddress不会为空
func (f *GlobalMethodStrategy) Execute(threadStore *structdef.ThreadStore) {
	content := threadStore.Code.LineContent
	index1 := strings.Index(content, ".")
	methodName := content[index1+1:] //方法名称
	funName, funParams := SubFunctionCallNameAndParam(methodName)
	FunctionCallExecute(threadStore, funName, funParams)
}
